Usage example
var latlng = L.latLng(50.5, 30.5);
All Leaflet methods that accept LatLng objects also accept them in a simple Array form and simple object form (unless noted otherwise), so these lines are equivalent:
所有接受LatLng对象的Leaflet方法也以简单数组形式和简单对象形式接受它们(除非另有说明),因此这些行是等价的:
map.panTo([50, 30]);
map.panTo({lng: 30, lat: 50});
map.panTo({lat: 50, lng: 30});
map.panTo(L.latLng(50, 30));
Note that LatLng does not inherit from Leaflet’s Class object, which means new classes can’t inherit from it, and new methods can’t be added to it with the include function.
请注意,LatLng不从Leaflet的Class对象继承,这意味着新的类不能从它继承,并且不能使用include函数向它添加新的方法。
Creation
Methods
| Method | Returns | Description |
|---|---|---|
equals(<LatLng> otherLatLng, <Number> maxMargin?) | Boolean | Returns true if the given LatLng point is at the same position (within a small margin of error). The margin of error can be overridden by setting maxMargin to a small number.如果给定的LatLng点位于同一位置(在较小的误差范围内),则返回true。通过将maxMargin设置为一个较小的数字,可以覆盖误差范围。 |
toString() | String | Returns a string representation of the point (for debugging purposes). 返回点的字符串表示形式(用于调试)。 |
distanceTo(<LatLng> otherLatLng) | Number | Returns the distance (in meters) to the given LatLng calculated using the Spherical Law of Cosines.返回使用球面余弦定律计算的给定LatLng的距离(以米为单位)。 |
wrap() | LatLng | Returns a new LatLng object with the longitude wrapped so it’s always between -180 and +180 degrees.返回一个新的LatLng对象,该对象的经度始终在-180和+180度之间。 |
toBounds(<Number> sizeInMeters) | LatLngBounds | Returns a new LatLngBounds object in which each boundary is sizeInMeters/2 meters apart from the LatLng.返回一个新的LatLngBounds对象,其中每个边界与LatLng相距sizeInMeters/2米。 |
Properties
| Property | Type | Description |
|---|---|---|
lat | Number | Latitude in degrees 纬度(度) |
lng | Number | Longitude in degrees 经度(度) |
alt | Number | Altitude in meters (optional) 海拔高度(米)(可选) |